let nums = [2, 7, 11, 15], target = 13

var twoSum = function (nums, target) {
  const obj = {}
  for (let i = 0; i < nums.length; i++) {
    if (obj[target - nums[i]] !== undefined) {
      return [obj[target - nums[i]], i]
    }
    obj[nums[i]] = i
  }
  return []
};

console.log(twoSum(nums, target));

// O(n^2)